package com.qfedu.mesadmin.sys.user.service.impl;

import com.qfedu.mes.entity.sys.SysUser;
import com.qfedu.mes.exception.CommonException;
import com.qfedu.mesadmin.sys.user.dao.SysUserDao;
import com.qfedu.mesadmin.sys.user.params.LoginParam;
import com.qfedu.mesadmin.sys.user.service.SysUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class SysUserServiceImpl implements SysUserService {

    @Resource
    private SysUserDao sysUserDao;

    @Override
    public SysUser login(LoginParam loginParam) {

        SysUser sysUser = sysUserDao.selectByName(loginParam.getUsername());
        if (sysUser == null) {
            throw new CommonException("用户名错误");
        }
        if (!sysUser.getPassword().equals(loginParam.getPassword())) {
            throw new CommonException("密码错误");
        }

        return sysUser;
    }
}
